package com.woniu40.petai_user.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu40.petai_user.entity.Goods;
import com.woniu40.petai_user.entity.GoodsType;
import com.woniu40.petai_user.entity.ProductType;
import com.woniu40.petai_user.mapper.GoodsMapper;
import com.woniu40.petai_user.mapper.GoodsTypeMapper;
import com.woniu40.petai_user.vo.GoodsVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class GoodsService {

    @Autowired
    GoodsMapper goodsMapper;

    @Autowired
    GoodsTypeMapper goodsTypeMapper;

    public PageInfo<GoodsVo> findGoodsByPage(Integer pageNum,Integer pageSize, String productTypeName,
                                                   String goodsTypeName,
                                                   String goodsName,
                                                   String brandName,
                                                   BigDecimal minPrice,
                                                  BigDecimal maxPrice,
                                                   Integer orderId  ){
        PageHelper.startPage(pageNum,pageSize);

        List<GoodsVo> goodsVos = goodsMapper.selectBySoMany(productTypeName, goodsTypeName, goodsName, brandName, minPrice, maxPrice,orderId);

        PageInfo<GoodsVo> goodsVoPageInfo = new PageInfo<>(goodsVos);
        return goodsVoPageInfo;
    }

    //根据id查询商品
    public Goods findGoodsById(Integer goodsId){
        Goods goods = goodsMapper.selectByPrimaryKey(goodsId);
        return goods;
    }

    public List<GoodsVo> findBySaleCount(){
        List<GoodsVo> goods = goodsMapper.selectBySaleCount();
        return goods;
    }

    public GoodsVo findVoByGoodsId(Integer goodsId){
        GoodsVo goodsVo = goodsMapper.selectByGoodsId(goodsId);
        return goodsVo;
    }
}
